package com.ldl.origami.controller.system;

import com.ldl.origami.origamiService.NewsService;
import com.ldl.origami.origamiService.RegisterService;
import com.ldl.origami.websocket.SystemWebSocketHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 功能描述:注册controller
 * 作者: LDL
 * 创建时间: 2014/7/13 11:46
 */
@Controller
public class RegisterController {

    static Logger logger = LoggerFactory.getLogger(RegisterController.class);

    @Autowired(required = false)
    private RegisterService registerService;

    @Autowired(required = false)
    private NewsService newsService;

    @Bean
    public SystemWebSocketHandler systemWebSocketHandler() {
        return new SystemWebSocketHandler();
    }
    /**
     * 跳转到注册页面
     * @return
     */
    @RequestMapping(value = "/registerIndex")
    public String registerIndex(){
        return "regist";
    }

    /**
     * 检测用户名是否存在
     * @param request
     * @return
     */
    @RequestMapping(value = "/checkUserName")
    @ResponseBody
    public String checkUserName(HttpServletRequest request){
        String userName = request.getParameter("userName");
        String result = registerService.checkUserName(userName);
        return result;
    }
    /**
     * 检测邮箱是否存在
     * @param request
     * @return
     */
    @RequestMapping(value = "/checkEmail")
    @ResponseBody
    public String checkEmail(HttpServletRequest request){
        String email = request.getParameter("email");
        String result = registerService.checkEmail(email);
        return result;
    }

}
